<script setup>
// vue2的写法
// props:['money','car']

import { computed } from 'vue';

// defineProps(['money', 'car'])
const props = defineProps({
    money: Number,
    car: {
        type: String,
        default: '五菱宏光'
    }
})
/* 
通过调用 defineProps 的方法，拿到父组件的数据，并且存放到 props
*/
console.log('props', props);
const doubleMoney = computed(() => {
    return props.money * 2
})

const emits = defineEmits(['changeMoney'])
const addMoney = () => {
    // vue2, this.$emits('changeMoney', 1000)
    emits('changeMoney', 1000)
}

</script>

<template>
    <h1>子组件</h1>
    <div>{{ money }} - {{ car }}</div>
    <div>双倍金钱{{ doubleMoney }}</div>
    <button @click="addMoney">点我加1000</button>
</template>
